home *** CD-ROM | disk | FTP | other *** search
- /*
- Y2K-ok Fix the year 2000 problem (!)
-
- MacHack98 bh noEsis Software Construction
- bspence bspence@mdli.com
- */
-
- //****************************************************************
- // I N C L U D E S
-
- #include <Types.h>
- #include <Memory.h>
- #include <A4Stuff.h>
- #include <SetUpA4.h>
- #include <Quickdraw.h>
- #include <LowMem.h>
- #include <Errors.h>
- #include <Gestalt.h>
- #include <Resources.h>
- #include <Events.h>
- #include <Windows.h>
- #include <Retrace.h>
-
- #include <MixedMode.h>
-
-
-
- //****************************************************************
- // C O N S T A N T S
- #define FALSE false
- #define TRUE true
- #define NIL 0L
-
-
- //******************************
- // The 68k code goes in a normal INIT resource.
- // Be sure this is set to "system heap/locked".
-
- #define kInitRezType 'INIT'
- #define kInitRezID 300
-
- #define kMinSystemVersion (0x0603)
-
-
- // ShowInit
- #define kOkMac 128
- #define kNotMac 132
-
-
- //****************************************************************
- // G L O B A L S
-
- struct NInitGlobals
- {
- SysEnvRec gSystemInfo;
- long gInfo; // 1=68k,2=PPC
-
- VBLTask gVBLTask;
-
- };
- typedef struct NInitGlobals NInitGlobals;
-
- NInitGlobals *gP;
-
-
- //****************************************************************
- // F O R W A R D S
-
- OSErr DoInstall( void);
- pascal void DoVBL(void);
-
-
- extern void ShowIconFamilyAnim(short iconId, short cnt);
- extern void ShowIconFamily(short iconId);
-
-
- //****************************************************************
- void main( void )
- {
- long oldA4, lRes;
- Handle initH = nil; /* Handle to our own INIT resource */
- OSErr err = noErr;
- unsigned long t;
-
- oldA4 = SetCurrentA4(); /* Get the proper value of A4 into A4 */
- RememberA4(); /* save into self-modifying code */
-
-
- // Allocate globals struct
- gP = (NInitGlobals*) NewPtrSysClear( sizeof(NInitGlobals));
- if ( !gP ) {
- err = memFullErr;
- goto DONE;
- }
-
- // Get minimal System Info:
- err = SysEnvirons( 1, &gP->gSystemInfo );
- if ( err )
- goto DONE;
- if ( gP->gSystemInfo.systemVersion < kMinSystemVersion ) {
- err = -1;
- goto DONE;
- }
-
- // Prepare to Detach ourselves...
- initH = Get1Resource( kInitRezType, kInitRezID );
- if ( !initH ) {
- err = resNotFound;
- goto DONE;
- }
-
- // Call Gestalt:
- // Gestalt will return an err when SysArc is unimplemented
- err = Gestalt( gestaltSysArchitecture, &gP->gInfo );
- if ( err) gP->gInfo = gestalt68k;
-
-
- err = DoInstall();
-
-
- DONE:
- if ( err ) {
- ShowIconFamily( kNotMac );
- if ( gP )
- DisposePtr( (Ptr)gP );
- } else {
- ShowIconFamilyAnim( kOkMac, 4 );
- DetachResource( initH);
- MoveHHi( (Handle)initH); HLock( (Handle)initH);
- }
-
- RestoreA4( oldA4 ); /* restore previous value of A4 */
- }
-
-
-
- //****************************************************************
- // DoInstall
- //****************************************************************
- #define kVBLStartInterval 200
- #define kVBLJamInterval 1
-
- OSErr DoInstall( void )
- {
- long oldA4;
- NInitGlobals *locGPtr;
-
- oldA4 = SetUpA4();
- locGPtr = gP;
- RestoreA4( oldA4 );
-
- locGPtr->gVBLTask.qLink = 0;
- locGPtr->gVBLTask.qType = vType;
- locGPtr->gVBLTask.vblAddr = DoVBL;
- locGPtr->gVBLTask.vblCount = kVBLStartInterval;
- locGPtr->gVBLTask.vblPhase = 0;
-
- VInstall( (QElemPtr)&locGPtr->gVBLTask);
-
- return noErr;
- }
-
-
- //****************************************************************
- // DoVBL
- //****************************************************************
- VBLTask *GetVBLInfo( void ) = { 0x2008 }; /* MOVE.L A0,D0 */
-
- #define kY2K_Ticks 0xB492F3FF
-
- pascal void DoVBL(void)
- {
- VBLTask *curVBLInfo;
- unsigned long cmpT;
-
- curVBLInfo = GetVBLInfo();
-
- curVBLInfo->vblCount = kVBLStartInterval;
-
- cmpT = kY2K_Ticks - *(unsigned long*)0x20C;
- if ( cmpT < 0x10 ) {
-
- curVBLInfo->vblCount = kVBLJamInterval;
- // Keep that Bad 'ol Year 2000 at Bay forever !
- *(unsigned long*)0x20C = kY2K_Ticks - 0xF;
-
- } else if ( cmpT < 0x100 ) {
-
- curVBLInfo->vblCount = kVBLJamInterval;
- // or slow it down a little
- *(unsigned long*)0x20C = *(unsigned long*)0x20C - 1;
- }
-
- return;
- }
-
-
- //***********************************************************************************
- // E N D O F L I S T I N G
-